import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  list = '/system-service/tenantUser/pageAllUser',
  get = '/system-service/tenantUser/getUserDetails',
  assignUser='/system-service/tenantUser/assignUser',
  edit='/system-service/tenantUser/update',
  getUserRole = '/system-service/user/listUserRole',
  duplicateCheck = '/system-service/duplicate/check',
  deleteUser = '/system-service/tenantUser/delete',
  deleteBatch = '/system-service/tenantUser/deleteBatch',
  allRolesList = '/system-service/role/listAllRole',
  allTenantList = '/system-service/tenant/listAll',
  allPostList = '/system-service/position/listAll',
  listUserDept = '/system-service/tenantUser/listUserDept',
  listTenant = '/system-service/user/profile/listTenant',
}

/**
 * 列表接口
 * @param params
 */
export const list = (params) => 
  defHttp.get({url: Api.list, params});

/**
 * @param params
 */
export const getUserDetails = (params) => 
  defHttp.get({url: Api.get, params});


/**
 * 用户角色接口
 * @param params
 */
export const getUserRoles = (params) =>
  defHttp.get({url: Api.getUserRole, params}, {errorMessageMode: 'none'});

/**
 * 删除用户
 */
export const deleteUser = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteUser, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除用户
 * @param params
 */
export const batchDeleteUser = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 分配用户
 */
export const assignUser = (params, handleSuccess) => {
  return defHttp.post({url: Api.assignUser, params}).then(() => {
    handleSuccess();
  });
}


/**
 * 更新用户
 * @param params
 */
export const updateUser = (params) => {
  return defHttp.post({url: Api.edit, params});
}
/**
 * 唯一校验
 * @param params
 */
export const duplicateCheck = (params) =>
  defHttp.get({url: Api.duplicateCheck, params},{isTransformResponse:false});
/**
 * 获取全部角色
 * @param params
 */
export const getAllRolesList = (params) =>
  defHttp.get({url: Api.allRolesList, params});
/**
 * 获取全部租户
 */
export const getAllTenantList = (params) =>
  defHttp.get({url: Api.allTenantList, params});
